﻿using PostSharp.Aspects;
using PostSharp.Serialization;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace JGSY.SerialCommunication.UpperComputer.Core.AOP
{
    [PSerializable]
    public class LogAspect : OnMethodBoundaryAspect
    {
        public override void OnEntry(MethodExecutionArgs args)
        {
            Console.WriteLine($"[Log] 进入方法: {args.Method.Name}, 参数: {string.Join(", ", args.Arguments)}");
        }

        public override void OnExit(MethodExecutionArgs args)
        {
            Console.WriteLine($"[Log] 退出方法: {args.Method.Name}, 返回值: {args.ReturnValue}");
        }

        public override void OnException(MethodExecutionArgs args)
        {
            Console.WriteLine($"[Error] 方法 {args.Method.Name} 抛出异常: {args.Exception.Message}");
        }

    }
}
